<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>apply方法</title>
</head>

<body>
    <script>
        const student = {
            name: '张三'
        }

        function fn(x, y) {
            console.log(this); // student
            console.log(x + y); // 3
        }

        // apply方法传参时需要传数组
        fn.apply(student, [1, 2])

        // apply方法求数组最大值
        const arr = [1, 2, 3, 4, 5, 9, 8, 7]
        console.log(Math.max.apply(null, arr)); // 9
    </script>
</body>

</html>